package jsyf.oa.web.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.ProvinceFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Lenovo on 2017/12/9.
 */
@Api(value = "行政区域", description = "行政区域")
@Controller
@RequestMapping("/province")
public class ProvinceController {
    @Autowired
    private ProvinceFacade provinceFacade;

    @RequestMapping(value = "/getTreeNodes.json", method = RequestMethod.POST)
    public void getTreeNodes(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> result = provinceFacade.getTreeNodes();
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }

    @RequestMapping(value = "/getProvinceByParentId.json", method = RequestMethod.POST)
    public void getProvinceByParentId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = JSON.parseObject(jsonData);
        String parentId = obj.getString("parentId");
        List<JSONObject> result = provinceFacade.getProvinceByParentId(parentId);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }
}
